<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/inc/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息列表</title>
<%@ include file="/inc/head.jsp"%>
<script type="text/javascript">
	var grid;
	$(function() {
		grid = $('#grid')
				.datagrid(
						{
							title : '',
							url : '${ctx}/sys/user/0/0',
							striped : true,
							rownumbers : true,
							pagination : true,
							idField : 'id',
							sortName : 'createDate',
							sortOrder : 'desc',
							pageSize : 50,
							pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,
									400, 500 ],
							frozenColumns : [ [ {
								field : 'id',
								checkbox : true
							}, {
								width : '100',
								title : '登录名',
								field : 'username',
								sortable : true
							}, {
								width : '80',
								title : '姓名',
								field : 'fullName',
								sortable : true
							} ] ],
							columns : [ [
									{
										width : '150',
										title : '创建时间',
										field : 'createDate',
										sortable : true
									},
									{
										width : '150',
										title : '修改时间',
										field : 'createDate',
										sortable : true
									},
									{
										title : '操作',
										field : 'action',
										width : '90',
										formatter : function(value, row) {
											var str = '';
											str += sy
													.formatString(
															'<img class="iconImg ext-icon-note_edit" title="编辑" onclick="user.edit(\'{0}\');"/>',
															row.id);
											str += sy
													.formatString(
															'<img class="iconImg ext-icon-note_delete" title="删除" onclick="user.del(\'{0}\');"/>',
															row.id);
											return str;
										}
									} ] ],
							toolbar : '#toolbar'
						});
		user = {
			remove : function() {
				var ids = [];
				var rows = $("#grid").datagrid('getSelections');
				if (rows.length > 0) {
					$.messager.confirm('你确定永久删除该数据吗?', function(r) {
						if (r) {
							for ( var i = 0; i < rows.length; i++) {
								ids.push(rows[i].id);
							}
							$.ajax({
								url : "${ctx}/sys/user/deleteByIds",
								type : 'post',
								dataType : 'json',
								data : {
									ids : ids.join(',')
								},
								cache : false,
								success : function(d) {
									if (d.success) {
										$.sys.user.tip(d.msg);
										$.sys.user.reloadTable();
										$("#grid").datagrid('unselectAll');
										ids = '';
									}
								}
							});
						}
					});
				} else {
					$.sys.user.tip("请选择需要删除的数据");
				}
			},
			create : function() {
				var dialog = sy.modalDialog({
					title : '添加用户组信息',
					url : sy.contextPath + '/sys/user/create',
					width : 400,
					height : 300,
					buttons : [ {
						text : '保存',
						handler : function() {
							dialog.find('iframe').get(0).contentWindow
									.submitForm(dialog, grid, parent.$);
						}
					} ]
				});
			},
			del : function(id) {
				parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
					var url = "${ctx}/sys/user/" + id + "/delete";
					if (r) {
						$.post(url, function() {
							grid.datagrid('reload');
						}, 'json');
					}
				});
			},
			edit : function(id) {
				var dialog = parent.sy.modalDialog({
					title : '编辑用户信息',
					url : "${ctx}/sys/user/update/" + id,
					width : 400,
					height : 300,
					buttons : [ {
						text : '编辑',
						iconCls : 'icon-save',
						handler : function() {
							dialog.find('iframe').get(0).contentWindow
									.submitForm(dialog, grid, parent.$);
						}
					} ]
				});
			}
		};
	});
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<div style="padding: 0 0 0 7px; color: #333;">
			<form id="searchForm">
				<table>
					<tr>
						<td>登录名</td>
						<td><input name="search.username_like" style="width: 80px;" /></td>
						<td>姓名</td>
						<td><input name="search.fullName_like" style="width: 80px;" /></td>
						<td>创建时间</td>
						<td><input name="search.createDate_gt" class="Wdate"
							onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
							readonly="readonly" style="width: 120px;" />-<input
							name="search.createDate_lt" class="Wdate"
							onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
							readonly="readonly" style="width: 120px;" /></td>
						<td>状态</td>
						<td><esform:select path="search.status_eq"
								cssClass="easyui-combobox">
								<esform:option label="所有" value="" />
								<esform:options items="${statusList}" itemLabel="info" />
							</esform:select>
						<td><a href="javascript:void(0);" class="easyui-linkbutton"
							data-options="iconCls:'ext-icon-zoom',plain:true"
							onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a><a
							href="javascript:void(0);" class="easyui-linkbutton"
							data-options="iconCls:'ext-icon-zoom_out',plain:true"
							onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div>
			<a href="javascript:void(0);" class="easyui-linkbutton"
				data-options="iconCls:'ext-icon-note_add',plain:true"
				onclick="user.create();">添加</a>
		</div>
	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>